# -*- coding: utf-8 -*-

# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://docs.scrapy.org/en/latest/topics/item-pipeline.html

import psycopg2
import psycopg2.extras

class ZhipinspiderPipeline(object):

    def __init__(self):
        #  self.conn = self.gp_connect();
        # self.cur = self.conn.cursor(cursor_factory=psycopg2.extras.RealDictCursor)
        print("init")

    def close_spider(self,spider):
        # self.cur.close()
        # self.conn.close()
        print("close")

    def gp_connect(self):
        try:
            db = psycopg2.connect(dbname="postgres",
                                  user="gpadmin",
                                  password="",
                                  host="172.26.168.140",
                                  port="5432")

            return db
        except psycopg2.DatabaseError as e:
            print("could not connect to Greenplum server", e)

    def process_item(self, item, spider):
       # self.cur.execute("insert into boos values (item['title'],item['salary'],item['company'],item['url'],item['work_addr'],item['industry'],item['company_size'],item['recruiter'],item['publish_date'])")
       # self.conn.commit()
       print(item)




